package com.hlf.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zouwenjun
 * @date 2017年3月10日 上午11:21:16
 */
public class ValidateUtils {

    private static final Logger log=LoggerFactory.getLogger(ValidateUtils.class);

    //判断手机号码格式/^1\d{10}$/;
    public static boolean isMobileNO(String mobile){
        Pattern p = Pattern.compile("^1\\d{10}$");
        Matcher m = p.matcher(mobile);
        log.info("手机号码校验{}",(m.matches()));
        return m.matches();
    }

    //校验身份证号码位数和最后一位
    public static boolean isIDCardNO(String IDCardNo){
        //Pattern p = Pattern.compile("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)");
        Pattern p=Pattern.compile("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");
        Matcher m = p.matcher(IDCardNo);
        log.info("校验身份证号码位数和最后一位{}",(m.matches()));
        return m.matches();
    }

    //校验固定电话
    public static boolean isFixedPhone(String fixedPhone){
        Pattern p=Pattern.compile("(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|" +
                "(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)");  
        Matcher m = p.matcher(fixedPhone);
        log.info("校验固定电话{}",(m.matches()));
        return m.matches();
    }  

}
